package top.boycharse.blog.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import top.boycharse.blog.bean.Response.BaseResponse;
import top.boycharse.blog.bean.request.UserInfo;
import top.boycharse.blog.dao.bean.User;
import top.boycharse.blog.dao.service.UserService;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/login")
    public String login() {
        return "请先登录!";
    }

    @PostMapping("/register")
    public BaseResponse<String> register(@RequestBody UserInfo userInfo) {
        // TODO 更进一步改进
        User user = new User(userInfo);
        userService.saveUser(user);

        return BaseResponse.buildSuccessMsg("注册成功");
    }
}
